package com.wc.算法提高课.A第一章_动态规划.单调队列优化DP.旅行问题;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/5/13 22:07
 * @description https://www.acwing.com/problem/content/1090/
 */
public class Main {
    /**
     * 思路: 到达下一个点是不事还有油,
     * 我们只需要存当前车站的油到达下一个车站距离的差值,
     * 取前缀和, 如果说区间 前缀和当中有最小的值大于等于0,那就说明这个起点是可以环绕的
     * 那就用到了单调队列, 看范围内最小的前缀和
     * 还需要考虑顺时针与逆时针
     * 那就用到了破环成链
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 2000010;
    static int[] o = new int[N], d = new int[N];
    static long[] s = new long[N];
    static int[] q = new int[N];
    static boolean[] ans = new boolean[N];
    static int hh = 1, tt = 0;
    static int n;

    public static void main(String[] args) {
        n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            o[i] = o[i + n] = sc.nextInt();
            d[i] = d[i + n] = sc.nextInt();
        }
        // 顺时针, 找前缀和里面最小的看是否 < 0如果小于0就说明他不能绕一圈
        for (int i = 1; i <= 2 * n; i++) {
            s[i] = s[i - 1] + o[i] - d[i];
        }

        for (int i = 1; i <= 2 * n; i++) {
            if (i <= n) {
                while (hh <= tt && s[i] <= s[q[tt]]) tt--;
                q[++tt] = i;
            } else {
                if (s[q[hh]] - s[i - n - 1] >= 0) ans[i - n] = true;
                while (i - n == q[hh]) hh++;
                while (hh <= tt && s[i] <= s[q[tt]]) tt--;
                q[++tt] = i;
            }
        }
        // 逆时针，同理, 逆向前缀和
        d[0] = d[n];
        for (int i = n * 2; i >= 1; i--) {
            s[i] = s[i + 1] + o[i] - d[i - 1];
        }
        hh = 1;
        tt = 0;
        for (int i = 2 * n; i >= 1; i--) {
            if (i > n) {
                while (hh <= tt && s[i] <= s[q[tt]]) tt--;
                q[++tt] = i;
            } else {
                if (s[q[hh]] - s[i + n + 1] >= 0) ans[i] = true;
                while (i + n == q[hh]) hh++;
                while (hh <= tt && s[i] <= s[q[tt]]) tt--;
                q[++tt] = i;
            }
        }
        for(int i = 1; i <= n; i++){
            if (ans[i]) out.println("TAK");
            else out.println("NIE");
        }
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
